{% extends 'base.html' %}

{% block body %}
{{ include('failed-attempt.html') }}

<!-- Modal for reset password -->
<div class='modal fade' id='resetModal' tabindex='-1' role='dialog' aria-labelledby='resetModalLabel' aria-hidden='true'>
  <div class='modal-dialog modal-dialog-centered' role='document'>
    <div class='modal-content'>
      <div class='modal-header'>
        <h5 class='modal-title' id='resetModalLabel'>{{ 'Reset your password'|trans }}</h5>
        <button type='button' class='close' data-dismiss='modal' aria-label='Close'>
          <span aria-hidden='true'>&times;</span>
        </button>
      </div>
      <div class='modal-body' data-wait='{{ 'Please wait…' }}'>
        <form name='resetPass' method='post' action='app/controllers/ResetPasswordController.php'>
          <input class='form-control' placeholder='{{ 'Enter your email address'|trans }}' name='email' type='email' required />
          <div class='text-center'>
            <button class='button btn btn-primary mt-2' type="submit" name="Submit">{{ 'Send reset link'|trans }}</button>
          </div>
        </form>
      </div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-secondary' data-dismiss='modal'>{{ 'Close'|trans }}</button>
      </div>
    </div>
  </div>
</div>

<section class='text-center'>
    <img src='app/img/logo.png' alt='elabftw' title='elabftw' class='col-md-3' />
  {% if App.Session.has('team_selection_required') %}
    <form method='post' action='app/controllers/LoginController.php'>
      <input type='hidden' name='auth_type' value='team'>
      <!-- form key -->
      {{ App.Csrf.getHiddenInput|raw }}
      <div class='col-md-4 mx-auto mt-4 text-left form-group'>
        <label for='team_selection_select'>{{ 'Your account is linked to several teams. Select in which team you want to log in'|trans }}</label>
        <select name='selected_team' id='team_selection_select' class='form-control'>
          {% for team in App.Session.get('team_selection') %}
            <option value='{{ team.id }}'>{{ team.name }}</option>
          {% endfor %}
        </select>
      </div>
      <button type='submit' class='button btn btn-primary' name='Submit'>{{ 'Login'|trans }}</button>
    </form>
  {% elseif App.Request.server.get(App.Config.configArr.extauth_remote_user) %}
    <!-- user is already authed with external auth, so just present a continue button
      we don't autologin anymore -->
      <form method='post' id='login' action='app/controllers/LoginController.php' autocomplete='off'>
        <!-- form key -->
        {{ App.Csrf.getHiddenInput|raw }}
        <input type='hidden' name='auth_type' value='external'>
        <h2 class='mt-4'>{{ 'You are already authenticated'|trans }}</h2>
        <br>
        <button type='submit' class='button btn btn-primary' name='Submit'>{{ 'Continue'|trans }}</button>
      </form>
    {% else %}

    {% if showLocal %}
      <!-- Login form , the id is for an acceptance test -->
      <form method='post' id='login' action='app/controllers/LoginController.php' autocomplete='off'>
        <!-- form key -->
        {{ App.Csrf.getHiddenInput|raw }}
        <h2 class='mt-4'>{{ 'Login to your account'|trans }}</h2>
        <br>
        <div class='col-md-4 mx-auto text-left form-group'>
          <label for='email'>{{ 'Email'|trans }}</label>
          <input class='form-control mb-4' id='email' name='email' type='email' value='{{ App.Session.has('email') ? App.Session.get('email') }}' required />
          <label for='password'>{{ 'Password'|trans }}</label>
          <!-- add tabindex=-1 to the forget password so we can switch from login to password with tab -->
          <a href='#' class='align_right underlined resetPassword modalToggle' tabindex='-1' data-modal='resetModal'>{{ 'Forgot password?'|trans }}</a>
          <div class='input-group'>
            <input class='form-control' id='password' name='password' type='password' required />
            <div class='input-group-append'>
              <span class='btn btn-light input-border togglePassword' tabindex='-1' data-toggle='#password'><i class='fas fa-eye' aria-hidden='true'></i></span>
            </div>
          </div>

          <!-- Remember me checkbox -->
          <div class='form-check mt-2'>
            <input type='checkbox' class='form-check-input' checked name='rememberme' id='rememberme' />
            <label for='rememberme' class='form-check-label'>{{ 'Remember me'|trans }}</label>
          </div>
        </div>

        {% if App.Config.configArr.ldap_toggle %}
        <!-- Select login type (local or ldap) -->
        <div class='form-check form-check-inline'>
          <input class='form-check-input' type='radio' name='auth_type' id='auth_type_local' value='local' checked>
          <label class='form-check-label' for='auth_type_local'>{{ 'Local'|trans }}</label>
        </div>
        <div class='form-check form-check-inline'>
          <input class='form-check-input' type='radio' name='auth_type' id='auth_type_ldap' value='ldap'>
          <label class='form-check-label' for='auth_type_ldap'>LDAP</label>
        </div>
        {% else %}
          <input type='hidden' name='auth_type' value='local'>
        {% endif %}

        <!-- Login button -->
        <button type='submit' class='button btn btn-primary' name='Submit'>{{ 'Login'|trans }}</button>
      </form>
      <p>{{ "Don't have an account? %sRegister%s now!"|trans|format(
        "<a href='register.php'>",
        "</a>")|raw }}</p>

    {% endif %}

    {% if App.Config.configArr.saml_toggle %}
      <div class='separator col-md-4 mx-auto'></div>
      <h2>{{ 'Login through your institution'|trans }}</h2>
      <br>
      <form method='post' class='form-group' id='saml-login' action='app/controllers/LoginController.php' autocomplete='off'>
        <input type='hidden' name='auth_type' value='saml'>
        {{ App.Csrf.getHiddenInput|raw }}
        <div class='form-group col-md-4 mx-auto'>
          <label for='idp_login_select'>{{ 'Select an identity provider'|trans }}</label>
          <select name='idpId' class='form-control' id='idp_login_select'>
            {% for idp in idpsArr %}
              {% if idp.active %}
                <option value='{{ idp.id }}'>{{ idp.name }}</option>
              {% endif %}
            {% endfor %}
          </select>
          <button class='button btn btn-primary mt-2' type='submit' name='submit'>{{ 'Login'|trans }}</button>
        </div>
      </form>
    {% endif %}

    {% if App.Config.configArr.anon_users %}
      <div class='separator col-md-4 mx-auto'></div>
      <h2>{{ 'Login as anonymous visitor'|trans }}</h2>
      <br>
      <form method='post' class='form-group' id='anon-login' action='app/controllers/LoginController.php' autocomplete='off'>
        <input type='hidden' name='auth_type' value='anon'>
        {{ App.Csrf.getHiddenInput|raw }}
        <div class='form-group mx-auto col-md-4'>
          <label for='anon_login_select'></label>
          <div class='input-group mb-2'>
            <div class='input-group-prepend'>
              <div class='input-group-text'>{{ 'Select a team'|trans }}</div>
            </div>
            <select name='team_id' class='form-control' id='anon_login_select'>
              {% for team in teamsArr|filter(v => v.visible == 1) %}
                <option value='{{ team.id }}'>{{ team.name }}</option>
              {% endfor %}
            </select>
          </div>
          <button class='button btn btn-primary mt-2' type='submit' name='submit'>{{ 'Login'|trans }}</button>
        </div>
      </form>
    {% endif %}
  {% endif %}
</section>
{% endblock body %}
